<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 15:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<style>
    .createBtn{
        margin-top:6px;
        margin-bottom:10px
    }
    ul#sparks li a{
        cursor:pointer
    }
</style>
<div  id="content-header" class="row">
    <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
        <h1 class="page-title txt-color-blueDark" style="margin-left:-28px;margin-top:4px">
            <i class="fa fa-table fa-fw "></i>
            业务数据
        </h1>
    </div>
</div>
<div class="row">
         <div class="col-lg-3 col-sm-6 col-xs-12" style="cursor:pointer">
               <div id="ajax_client-list" class="main-box infographic-box colored emerald-bg">
                   <i class="fa fa-user"></i>
                   <span class="headline">客戶</span>
                   <span class="value">&nbsp;<s:property value="businessData.client"/></span>
                   <input type="hidden" id="selectedIds" value=""/>
               </div>
           </div>
            <div class="col-lg-3 col-sm-6 col-xs-12" style="cursor:pointer">
              <div id="ajax_linkman-list" class="main-box infographic-box colored green-bg">
                  <i class="fa fa-linkedin-square"></i>
                  <span class="headline">联系人</span>
                  <span class="value">&nbsp;<s:property value="businessData.link"/></span>
              </div>
           </div>
            <div class="col-lg-3 col-sm-6 col-xs-12" style="cursor:pointer">
                 <div id="ajax_proInfo-list" class="main-box infographic-box colored red-bg">
                     <i class="fa fa-book"></i>
                     <span class="headline">项目</span>
                     <span class="value">&nbsp;<s:property value="businessData.proInfo"/></span>
                 </div>
             </div>

           <div class="col-lg-3 col-sm-6 col-xs-12" style="cursor:pointer">
                <div id="ajax_feedback-list" class="main-box infographic-box colored purple-bg">
                     <i class="fa fa-comment"></i>
                     <span class="headline">反馈</span>
                     <span class="value">&nbsp;<s:property value="businessData.proBack"/></span>
                </div>
            </div>
</div>
<div id="business_data">
    <div class="row" style="padding:2px;padding-bottom: 5px">
        <div class="col-sm-12 col-md-12 col-lg-12">
            <div >
              <shiro:hasAnyRoles name="wechat">
                <form id="searchForm" method="post" action="">
                    <a id="ajax_client_btn_add" class="btn btn-default " data-toggle="modal"><i class="fa fa-lg fa-plus"></i> 新建客户信息表</a>
                    <a id="ajax_download_client_datas" class="btn btn-default btn-primary pull-right" href="javascript:void(0);"> <i class="fa fa-lg fa-hand-o-right"></i> 进入下载中心 </a>
                    <a id="ajax_export_client_datas" class="btn btn-default btn-primary pull-right" href="javascript:void(0);"> 客户信息数据导出 <i class="fa fa-lg fa-external-link"></i></a>
                </form>
              </shiro:hasAnyRoles>
            </div>
        </div>
    </div>
    <!-- rows -->
    <!-- widget grid -->
    <section id="widget-grid" class="">

        <!-- row -->
        <div class="row">
            <!-- NEW WIDGET START -->
            <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

                <!-- Widget ID (each widget will need unique ID)-->
                <div class="jarviswidget " id="wid-id-0" data-widget-editbutton="false"
                     data-widget-colorbutton="false"
                     data-widget-togglebutton="false"
                     data-widget-deletebutton="false"
                     data-widget-fullscreenbutton="true"
                     data-widget-custombutton="false"
                     data-widget-sortable="false">

                    <%--<header>--%>
                        <%--<span class="widget-icon"> <i class="fa fa-table"></i> </span>--%>
                        <%--<h2>客户信息列表</h2>--%>
                    <%--</header>--%>

                    <!-- widget div-->
                    <div>

                        <!-- widget edit box -->
                        <div class="jarviswidget-editbox">
                            <!-- This area used as dropdown edit box -->

                        </div>
                        <!-- end widget edit box -->

                        <!-- widget content -->
                        <div class="widget-body no-padding">

                            <div class="col-sm-12 col-md-12 col-lg-12">
                                <div class=" ">
                                    <div class="row" id="ajax_client_list_row">

                                        <table id="ajax_client_table" class="table table-striped table-bordered table-hover">
                                        </table>
                                        <div id="ajax_client_list_page">
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end widget content -->

                    </div>
                    <!-- end widget div -->

                </div>
                <!-- end widget -->

            </article>
            <!-- WIDGET END -->

        </div>

        <!-- end row -->

        <!-- end row -->

    </section>
<!-- end widget grid -->
</div>

<script type="text/javascript">
    // DO NOT REMOVE : GLOBAL FUNCTIONS!
    pageSetUp();


    function client_reload(){
        loadURL("ajax!client.action",$('#content'));
    }
    $("#ajax_client_btn_add").click(function(){
        loadURL("ajax-client!input.action",$('div#main div#business_data'));
    });

</script>
<script type="text/javascript">
    $(function(){
        $("#selectedIds").val("");
        load_client_jqGrid();
    });
    function load_client_jqGrid(){
        jQuery("#ajax_client_table").jqGrid({
            url:'ajax-client!list.action',
            datatype: "json",
            colNames:['客户名称',"客户简称",'客户性质',"所在区域","创建日期","操作","id"],
            colModel:[
                {name:'name',index:'name', width:120,search:true,sortable:true,
                    searchoptions:{sopt: ["cn"],clearSearch:true}},
                {name:'subname',index:'subname', width:80,sortable:false,search:false},
                {name:'type',index:'type', width:80,search:false},
                {name:'area',index:'area', search:false,width:200},
                {name:'createDate',index:'createDate', search:false,width:80},
                {name:'act',index:'act', width:210,sortable:false,search:false,fixed:true},
                {name:'id',index:'id',search:false,hidden:true},
            ],
            rowNum : 10,
            rowList:[10,20,30],
            pager : '#ajax_client_list_page',
            sortname : 'createDate',
            sortorder : "desc",
            gridComplete:function(){
                var ids=$("#ajax_client_table").jqGrid('getDataIDs');
                for(var i=0;i<ids.length;i++){
                    var cl=ids[i];
                    var selectedIds = $("#selectedIds").val();
                    if (selectedIds != "" && selectedIds != null){
                        var idsArr = selectedIds.split(",");
                        for (var s=0;s<idsArr.length;s++){
                            if (idsArr[s] == cl){
                                $("#ajax_client_table").jqGrid("setSelection", cl);
                            }
                           // break;
                        }
                    }
                    var rowData = $("#ajax_client_table").jqGrid("getRowData",cl);
                    var de="<button class='btn btn-default' data-original-title='查看' onclick=\"fn_client_read('"+cl+"');\"><i class='fa fa-eye'></i>查看</button>"+" ";
                    var dt="<button class='btn btn-default' data-original-title='删除' onclick=\"fn_client_destroy('"+cl+"');\"><i class='fa fa-eye'></i>删除</button>"+" ";
                    if($("#ajax_client_btn_add").length==0){
                        dt="";
                    }
                    jQuery("#ajax_client_table").jqGrid('setRowData',ids[i],{act:de+dt});
                }

                $(".ui-jqgrid-bdiv").css("overflow-x","hidden");

                jqGridStyle();
            },
            jsonReader: {
                root: "dataRows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems : false
            },
            caption : "<i class='fa fa-arrow-circle-right'></i> 客户列表",
            multiselect : true,
            rownumbers:true,
            gridview:true,
            shrinkToFit:true,
            viewrecords: true,
            autowidth: true,
            height:'auto',
            onSelectRow:function(rowId, status, e){
                //var str = $("#ajax_client_table").jqGrid('getGridParam','selrow');
                var ids = $("#selectedIds").val();
                if (ids != ""){
                    var idsArr = ids.split(",");
                    var isSelected = false;
                    for (var i=0; i<idsArr.length;i++){
                        if (idsArr[i] == rowId){
                            isSelected = true;
                            break;
                        }
                    }
                    if (status){
                        if (!isSelected)
                            $("#selectedIds").val(ids + "," +rowId);
                    }
                    else{
                        if (isSelected) {
                            if (idsArr.length < 2){
                                $("#selectedIds").val("");
                            }
                            else{
                                for (var i = 0; i < idsArr.length; i++) {
                                    if (idsArr[i] == rowId) {
                                        for (var j = i; j < idsArr.length - 1; j++) {
                                            idsArr[j] = idsArr[j + 1];
                                        }
                                        idsArr.length = idsArr.length - 1;
                                        break;
                                    }
                                }
                                $("#selectedIds").val(idsArr.join(","));
                            }
                        }
                    }
                }
                else{
                    $("#selectedIds").val(rowId);
                }
            },
            onSelectAll:function(aRowids, status, e){
                var ids = $("#selectedIds").val();
                if (ids != "") {
                    var idsArr = ids.split(",");
                    for (var i = 0; i < aRowids.length; i++) {
                        var isSelected = false;
                        var index = -1;
                        for (var j = 0; j < idsArr.length; j++) {
                            if (aRowids[i] == idsArr[j]) {
                                isSelected = true;
                                index = j;
                                break;
                            }
                        }
                        if (status) {
                            if (!isSelected) {
                                idsArr.push(aRowids[i]);
                            }
                        }
                        else {
                            if (isSelected) {
                                for (var n = index; n < idsArr.length - 1; n++) {
                                    idsArr[n] = idsArr[n + 1];
                                }
                                idsArr.length = idsArr.length - 1;
                            }
                        }
                    }
                    $("#selectedIds").val(idsArr.join(","));
                }
                else{
                    $("#selectedIds").val(aRowids.join(","));
                }
            },
            forceFit:true,
            loadComplete: function() {
            }
        });
        $(window).on('resize.jqGrid', function() {
            jQuery("#ajax_client_table").jqGrid('setGridWidth', $("#ajax_client_list_row").width());
        })
        jQuery("#ajax_client_table").jqGrid('filterToolbar',{searchOperators:false,stringResult:true});

        jQuery("#ajax_client_table").jqGrid('navGrid', "#ajax_client_list_page", {
            edit : false,
            add : false,
            del : false,
            search:false
        });
    };
    //编辑
    function fn_client_actions_edit(id){
        loadURL("ajax-client!read.action?keyId="+id,$('div#main div#business_data'));
    };

    function fn_client_read(id){
        loadURL("ajax-client!read.action?keyId="+id,$('div#main div#business_data'));
    }

    function fn_client_destroy(id){
        var vActionUrl = "<%=path%>/com/ajax-client!delete.action";
        data={keyId:id};
        ajax_action(vActionUrl,data,{},function(pdata){
            _show(pdata);
        });
        jQuery("#ajax_client_table").trigger("reloadGrid");
    }
</script>

<script type="text/javascript">

    $(function(){
        $("#ajax_client-list").click(function(){
            client_reload();
        });
        $("#ajax_linkman-list").click(function(){
            loadURL("ajax-linkman!show.action",$('div#main div#business_data'));
        });
        $("#ajax_proInfo-list").click(function(){
            loadURL("ajax-project!view.action",$('div#main div#business_data'));
        });
        $("#ajax_feedback-list").click(function(){
            loadURL("ajax-pro-back!view.action",$('div#main div#business_data'));
        });
    });

    $("#ajax_download_client_datas").click(function(){
        loadURL("ajax!downloadFile.action",$("#content"));
    });

    $("#ajax_export_client_datas").click(function(){
        //var ids = $("#ajax_client_table").jqGrid('getGridParam','selarrrow');
        if($("#selectedIds").val()==""){
            var data = {
                state:400,
                title:"操作状态",
                message:"请先勾选需要导出的客户信息"
            }
            _show(data);
            return;
        }
        else{
            $.SmartMessageBox({
                title : "确定导出客户信息数据吗？",
                content : "确定导出操作将进入创建导出文件队列，进入下载中心可查看导出文件执行情况。",
                buttons : '[取消][确认]'
            }, function(ButtonPressed) {
                if (ButtonPressed === "确认") {
                location.href = "ajax-import!exportData.action?keyId=client&idList="+$("#selectedIds").val();
                /*
                    ajax_action("ajax-import!exportData.action?keyId=client&idList="+$("#selectedIds").val(),null,{},function(pdata){
                        _show(pdata);
                    });*/
                }
            });
        }


    });
</script>
